package com.nariano.server.domain.engine.droolsimpl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.util.Assert;

import com.nariano.server.domain.entities.Area;
import com.nariano.server.domain.entities.AreaBoundaries;
import com.nariano.server.domain.entities.City;
import com.nariano.server.domain.entities.Location;
import com.nariano.server.domain.entities.Population;
import com.nariano.server.domain.entities.PopulationType;
import com.nariano.server.domain.entities.User;
import com.nariano.server.services.cityservice.CityService;
import com.nariano.server.services.mapservice.MapService;
import com.nariano.server.services.userservice.UserService;

public class MockMapCityService implements MapService, CityService, UserService {
    
    Map<Location, Area> map = new HashMap<Location, Area>();
	private Map<Integer, User> users = new HashMap<Integer, User>();
    
    public MockMapCityService() {
        List<Area> areas = Arrays.asList(getArea1(),getArea2());
        for (Area a : areas) {
            map.put(a.getLocation(), a);
        }
    }

    public void createMap(int size) {
        throw new UnsupportedOperationException("Not implemented");
    }

    private Area getArea2() {
        Area a = new Area(new Location(0,0));
        a.setId(1);
        System.out.println("Created " + a.toString());
        return a;
    }

    private Area getArea1() {
        Area a = new Area(new Location(0,1));
        a.setId(2);
        a.setCity(new City("Teststaden", new User("user","user","user").getId(), a.getLocation()));

        System.out.println("Created " + a.toString());
        return a;
    }

    public void deleteMap() {
        throw new UnsupportedOperationException("Not implemented");
    }

    public Area getArea(Location location) {
    	Assert.notNull(location);
        return map.get(location);
    }

    public List<Area> getAreas() {
        return new ArrayList<Area>(map.values());
    }

    public List<List<Area>> getAreas(Location center, int width) {
        throw new UnsupportedOperationException("Not implemented");
    }

    public void updateAreas(Area ... as) {
    	for (Area a : as) {
    		if (!map.containsKey(a.getLocation())) {
    			throw new IllegalArgumentException("Go away!!!");
    		}
    		if (a.getCity()!=null) {
    			a.getCity().setLocation(a.getLocation());
    		}
    		map.put(a.getLocation(), a);
    	}
    }
    
    public Area getArea(Integer id) {
		throw new UnsupportedOperationException("Implement");
	}

    public City createCity(City city) {
        throw new UnsupportedOperationException("Not implemented");
    }

    public void deleteCity(City city) {
        throw new UnsupportedOperationException("Not implemented");
    }

    public List<City> findCity(String name) {
        throw new UnsupportedOperationException("Not implemented");
    }

    public List<City> getCities() {
        throw new UnsupportedOperationException("Not implemented");
    }

    public List<City> getCities(User user) {
        throw new UnsupportedOperationException("Not implemented");
    }

    public City getCity(Location location) {
        throw new UnsupportedOperationException("Not implemented");
    }

    public void updateCity(City city) {
        // do nothing
    }

	public AreaBoundaries getBoundaries() {
		return new AreaBoundaries(1,2);
	}

	@Override
	public int getPopulationCount(Integer user, PopulationType type) {
		throw new UnsupportedOperationException("Implement");
	}

	@Override
	public Population moveOutRandomPopulation(Integer user) {
		throw new UnsupportedOperationException("Implement");
	}

	@Override
	public void deleteUser(User user) {
		throw new UnsupportedOperationException("Not implemented");
	}

	@Override
	public User findUserFromEmail(String email) {
		throw new UnsupportedOperationException("Not implemented");
	}

	@Override
	public User findUserFromUserName(String userName) {
		throw new UnsupportedOperationException("Not implemented");
	}

	@Override
	public List<User> getAllUsers() {
		throw new UnsupportedOperationException("Not implemented");
	}

	@Override
	public int getNofUsers() {
		throw new UnsupportedOperationException("Not implemented");
	}

	@Override
	public User insertUser(User user) {
		users.put(user.getId(),user);
		return  user;
	}

	@Override
	public void updateUser(User user) {
		// do nothing
	}

	@Override
	public User findUserFromId(Integer id) {
		return users.get(id);
	}

	@Override
	public List<User> findAttackers(Integer id) {
		throw new UnsupportedOperationException("Not implemented");
	}

	@Override
	public List<Population> getPopulation(Integer user) {
		throw new UnsupportedOperationException("Not implemented");
	}


}
